home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / CD-ROM Tools / CDPlay / Source / cdplay.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  8.9 KB  |  279 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // CDPlay.cpp
  3. //
  4. // ©1995 SynthoWare
  5. // Simple CD Audio Player that doesn't display track/disk time
  6. //
  7. // Programmed By: Deryk B Robosson
  8. // E-mail:        newlook@free.org
  9. // Snail-mail:    32609 Manistee
  10. //                Westland, MI  48186
  11. //                +1.313.990.3599
  12. //
  13. // Used: * AFrame 
  14. //         - Amiga C++ OOP Programmers Enhancements
  15. //         - By Jeffry A Worth
  16. //           - e-Mail: worth@emuvax.emich.edu
  17. //                     73410.1112@compuserve.com
  18. //         - And Deryk B Robosson
  19. //           - See above for bug reports etc.
  20. //
  21. //       * CDPlayer.library v37.0 on 29.5.1995
  22. //         - By Patrick Hess
  23. //         - e-Mail: poseidon@newswire.gun.de
  24. //                   poseidon@canta.gun.de
  25. //         - SMail: Patrick Hess
  26. //                  Holsteinstr. 27
  27. //                  41564 Kaarst
  28. //                  V+49-2131-6695556Q
  29. //////////////////////////////////////////////////////////////////////////////
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32. // Includes
  33. #include <exec/types.h>
  34. #include "aframe:cdplay/cdplay.hpp"
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <dos/dos.h>
  38. #include <libraries/cdplayer.h>
  39. #include <proto/cdplayer.h>
  40. #include <proto/dos.h>
  41. #include <proto/exec.h>
  42. #include <pragmas/cdplayer_pragmas.h>
  43. #include "aframe:include/amigaapp.hpp"
  44. #include "aframe:include/window.hpp"
  45. #include "aframe:include/rastport.hpp"
  46. #include "aframe:include/rect.hpp"
  47. #include "aframe:include/panel.hpp"
  48. #include "aframe:include/imagebutton.hpp"
  49. #include "aframe:cdplay/resources/Brushes_Select.res"
  50. #include "aframe:cdplay/resources/Brushes_Render.res"
  51. #include "aframe:cdplay/resources/About.res"
  52.  
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // GLOBAL VARS
  55. int CurTrack=1, paused=FALSE; // Always keep track of current track and paused status
  56. int result; // Keep a variable for return codes
  57. ULONG i=0, unit=2; // Default unit number change as necessary
  58. char text[40]="";
  59.  
  60. // Misc required structs for us to use
  61. struct IOStdReq *CD_Request;
  62. struct MsgPort  *CD_Port;
  63. struct Library  *CDPlayerBase = NULL;
  64. struct CD_TOC table;
  65. struct CD_Time cd_time;
  66. struct CD_Volume vol;
  67. struct CD_Info info;
  68.  
  69. ///////////////////////////////////////////////////////////////////////////////
  70. // About Window Class Definition
  71. // We have to tell the user about us a little bit don't we? ;)
  72.  
  73. class AboutWindow: public AFWindow
  74. {
  75. public:
  76.  
  77.   virtual void OnCreate();
  78.   virtual void OnGadgetUp(LPIntuiMessage imess);
  79.   virtual void OnCloseWindow(LPIntuiMessage imess);
  80.   virtual void DestroyWindow();
  81.  
  82.   AFPanel AboutPanel; // One panel for button
  83.   AFPanel info_panel; // One panel for Info
  84.   AFImageButton AboutButton; // One button!
  85. };
  86.  
  87. //////////////////////////////////////////////////////////////////////////////
  88. // ControlWindow Class Definition
  89. // Main window definitions for our primary input
  90.  
  91. class ControlWindow: public AFWindow
  92. {
  93. public:
  94.   virtual void OnCreate();
  95.   virtual void OnGadgetUp(LPIntuiMessage imess);
  96.   virtual void DestroyWindow();
  97.   virtual ULONG WindowFlags();
  98.  
  99.   AFImageButton Next, Prev, Stop, Play, Pause, About; // Our many image buttons
  100. };
  101.  
  102. //////////////////////////////////////////////////////////////////////////////
  103. // ControlWindow Implementation routines
  104. // What we do on an exit request from the user
  105.  
  106. void ControlWindow::DestroyWindow()
  107. {
  108.   if(CD_Request) CloseDevice((struct IORequest *) CD_Request); // Close the device
  109.   if(CD_Request) DeleteIORequest(CD_Request); // Delete the IORequest struct memory
  110.   if(CD_Port)    DeleteMsgPort(CD_Port);  // Delete the message port
  111.   if(CDPlayerBase) CloseLibrary(CDPlayerBase);  // Close the library file
  112.  
  113.   AFWindow::DestroyWindow(); // Destroy the window
  114.   delete this;  // Delete the object
  115. }
  116.  
  117. // We override the OnCreate() function so we can do some extra things that it
  118. // doesn't do for us.
  119. void ControlWindow::OnCreate()
  120. {
  121.   AFRastPort rp(this);
  122.  
  123.   if(!(CDPlayerBase=(struct Library*)OpenLibrary((UBYTE*)CDPLAYERNAME,(ULONG)CDPLAYERVERSION)))
  124.     DestroyWindow();
  125.  
  126.   CD_Port=CreateMsgPort();
  127.   CD_Request=(struct IOStdReq *) CreateIORequest(CD_Port,sizeof(struct IOStdReq));
  128.   OpenDevice((UBYTE * )"scsi.device",(ULONG)unit,(struct IORequest *) CD_Request,NULL);
  129.   CDReadTOC(&table,CD_Request);
  130.   CDTitleTime(&cd_time,CD_Request);
  131.   CDInfo(&info,CD_Request);
  132. }
  133. // We override the OnGadgetUP function so we can handle the messages accordingly
  134. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  135. {
  136.   AFRastPort rp(this);
  137.   AFRect rect, aboutrect;
  138.   AboutWindow *about;
  139.  
  140.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  141.   case ID_PLAY:  // User pressed PLAY button
  142.     CDPlay((UBYTE)CurTrack,table.cdc_NumTracks,CD_Request);  // Play first track
  143.     break;
  144.   case ID_PAUSE: // User pressed PAUSE Button
  145.     if(paused==TRUE) { // If we were paused
  146.       paused=FALSE;      // We aren't now!
  147.       CDResume(TRUE,CD_Request);  // Pause the player
  148.     } else {
  149.         paused=TRUE;  // If we weren't paused, we are now!
  150.         CDResume(FALSE,CD_Request);  // UnPause the player
  151.       }
  152.  
  153.     break;
  154.   case ID_STOP:  // User pressed STOP button
  155.     CDStop(CD_Request);  // Stop the player
  156.     break;
  157.  
  158.   case ID_NEXT:  // User pressed NEXT track button
  159.     CurTrack++;  // increase track number
  160.  
  161.     if(CurTrack>table.cdc_NumTracks) {  // if we are beyond total number of tracks
  162.       CurTrack=table.cdc_NumTracks;     // set current track to last avail track
  163.     } else {
  164.         CDPlay((UBYTE)CurTrack,(UBYTE)table.cdc_NumTracks,CD_Request); // Otherwise, play CurTrack
  165.       }
  166.     break;
  167.  
  168.   case ID_PREV:  // User Pressed PREV track button
  169.     CurTrack--;  // decrease track number
  170.  
  171.     if(CurTrack<1) {  // if we are smaller than track 1
  172.       CurTrack=1;     // set current track to track 1
  173.     } else {
  174.         CDPlay((UBYTE)CurTrack,(UBYTE)table.cdc_NumTracks,CD_Request);  // Otherwise, play CurTrack
  175.       }
  176.     break;
  177.  
  178.   case ID_ABOUT:  //User wants to know about us yeah, yeah, yeah!
  179.     aboutrect.SetRect(10,10,212,115);
  180.     about=new AboutWindow;
  181.     about->Create(m_papp,&aboutrect);  // Create our new window and wait...
  182.     break;
  183.  
  184.   default:
  185.     AFWindow::OnGadgetUp(imess);  // the message wasn't for us, return it to Intuition
  186.     break;
  187.   }
  188. }  
  189.  
  190. ULONG ControlWindow::WindowFlags()  // Added WindowFlags
  191. {
  192.   return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  193. }
  194.  
  195. //////////////////////////////////////////////////////////////////////////////
  196. // About Window Implementation routines
  197. //
  198. // Deryk Robosson
  199. // December 18,1995
  200. //
  201.  
  202. void AboutWindow::OnCreate() // What we are doing when our AboutWindow
  203. {                            // is being Created
  204.   AFRect rect;
  205.  
  206.   rect.SetRect(2,11,94,103); // Set up our panel because image buttons can't have
  207.                              // Borders on them...
  208.   AboutPanel.Create("",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
  209.  
  210.   rect.SetRect(4,13,92,101); // Set up the main image button
  211.   AboutButton.Create(this,&rect,ID_ABOUTBOX,&about_image,NULL);
  212.  
  213.   rect.SetRect(96,11,184,103); // Create a panel for our useless text to be place in
  214.   info_panel.Create("General Info",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
  215.  
  216.   AFWindow::RefreshGadgets(); // Refresh the gadgetlist so we can see the things
  217.                              // we just did! :)
  218. }
  219.  
  220. void AboutWindow::OnGadgetUp(LPIntuiMessage imess)
  221. {
  222.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  223.  
  224.   case ID_ABOUTPANEL: // Handle things when user presses any of the three buttons
  225.   case ID_ABOUTBOX:
  226.     AboutWindow::DestroyWindow();
  227.     break;
  228.   default:
  229.     AFWindow::OnGadgetUp(imess); //  Wasn't our message!?
  230.     break;
  231.   }
  232. }
  233.  
  234. void AboutWindow::OnCloseWindow(LPIntuiMessage imess)
  235. {
  236.   AboutWindow::DestroyWindow();
  237. }
  238.  
  239. void AboutWindow::DestroyWindow()
  240. {
  241.   AFWindow::DestroyWindow();
  242.   delete this;
  243. }
  244.  
  245. //////////////////////////////////////////////////////////////////////////////
  246. // MAIN
  247.  
  248. void main()
  249. {
  250.   AFAmigaApp theApp;
  251.   AFRect rect(10,10,178,60); // Size of our main window
  252.   ControlWindow win;
  253.  
  254.   win.Create(&theApp,&rect,"CDPlay");  // Create our main window
  255.  
  256.   rect.SetRect(2,2,24,35); // Create Previous button
  257.   win.Prev.Create(&win,&rect,ID_PREV,&prev_render_image,&prev_select_image);
  258.  
  259.   rect.SetRect(26,2,48,35); // Create Next button
  260.   win.Next.Create(&win,&rect,ID_NEXT,&next_render_image,&next_select_image);
  261.  
  262.   rect.SetRect(50,2,72,35); // Create Stop button
  263.   win.Stop.Create(&win,&rect,ID_STOP,&stop_render_image,&stop_select_image);
  264.  
  265.   rect.SetRect(74,2,96,35); // Create Play button
  266.   win.Play.Create(&win,&rect,ID_PLAY,&play_render_image,&play_select_image);
  267.  
  268.   rect.SetRect(98,2,120,35); // Create Pause button
  269.   win.Pause.Create(&win,&rect,ID_PAUSE,&pause_render_image,&pause_select_image);
  270.  
  271.   rect.SetRect(122,2,144,35); // Create About button
  272.   win.About.Create(&win,&rect,ID_ABOUT,&about_render_image,&about_select_image);
  273.  
  274.   win.RefreshGadgets(); // Let's refresh so you can see our work!
  275.  
  276.   theApp.RunApp(); // run the app and forget about it, it'll
  277.                    // take care of itself! ;) (isn't C++ wonderful??)
  278. }
  279.